@extends('admin.layouts.master')
@section('css')
    <link rel="stylesheet" href="{{asset('/css/admin/rfid_warehouse.css')}}">
@endsection
@section('content')
    @include('admin.layouts.message')
    {{--页面的头部位置--}}
    <div class="main_header clearfix">
        <div class="main_header_show clearfix">
            <span><a style="color:white;font-size: 18px" href="{{url('/admin/rfidmanage')}}">RFID管理</a><span style="color:white;font-size: 18px">&nbsp;&nbsp;>&nbsp;&nbsp;RFID码仓库</span></span>
        </div>
        <div class="main_box_right">
            @if(Auth::guard('admin')->user()->checkPermission('rfid.warehouse'))
            <div class="add_hover">
                <span onclick="downloadExcel()" style="color:#24a7f6;font-size: 18px;">模板下载</span>
            </div>
            @endif
                @if(Auth::guard('admin')->user()->checkPermission('rfid.warehouse'))
                {{--<a href="javascript:void(0);" class="addfile">--}}
                  <div class="add_hover" onmouseover="this.style.cursor='hand'">
                      <form action="" method="post" enctype="multipart/form-data" id="formlist">
                          {{csrf_field()}}
                          <input type="file" name="excel" style="position: absolute;width: 90px;height: 40px;opacity: 0;
                          -ms-filter: 'alpha(opacity=0)';cursor:pointer;"  value="" id="fileinput" onchange="fileupload()" multiple="multiple">
                        <img src="{{asset('images/lodingin_icon.png')}}" alt="">
                      <span style="color:orange" onmouseover="this.style.cursor='hand'">导入</span>
                      </form>
                   </div>
                {{--</a>--}}
                @endif

           </div>
        </div>

    {{--主要的内容--}}
    <div class="main_form clearfix">
        <!-- 表格 -->
        <div class="main_formlist">
            <table class="table table-bordered main_table">
                <tbody>
                <tr>
                    <th>商品序号</th>
                    <th>RFID码</th>
                    <th>添加时间</th>
                    <th>操作</th>

                </tr>
                @foreach($warehouses as $warehouse)
                <tr>
                    <td>{{$warehouse->product_id}}</td>
                    <td>{{$warehouse->rfid}}</td>
                    <td>{{$warehouse->created_at}}</td>
                    <td>
                        @if(Auth::guard('admin')->user()->checkPermission('rfid.warehouse'))
                            {{--<a href="{{url('/admin/rfidmanage/associated',['pro_id'=>$warehouse->id])}}" style="text-decoration: none;" class="guan_list"--}}
                               {{--onclick="if(confirm('确定要关联吗?')==false) return false;layer.msg('关联成功');">--}}
                                {{--关联</a>--}}
                            <span class="guan_list change" data-id="{{$warehouse->id}}" >
                            关联</span>
                        @endif
                    </td>
                </tr>
                @endforeach
                </tbody>

            </table>
        </div>
        <div class="boot_fenye clearfix">
            <div class="boot_page">
                <div class="boot_page_di">第<span class="">{{ $page = isset($_GET['page'])?$_GET['page']:1}}</span>页
                </div>
                <div  class="boot_page_total">共<span>{{$total_page}}</span>页
                </div>
                <div class="boot_choose">
                    {{$warehouses->render()}}
                </div>
            </div>
        </div>
    </div>

@endsection
@section('js')
    {{--关联关系--}}
    <script>
        $(".change").click(function () {
            var id = $(this).data("id");
            if(confirm("确定要关联吗?")){
                $.ajax({
                    url: '/admin/rfidmanage/associated',
                    type: 'get',
                    data: {'id':id},
                    success: function (res) {
                        if (res.status == 0) {
                            layer.msg(res.msg);
                        } else {
                            layer.msg(res.msg, {icon: 1}, function () {
                                location.href = '/admin/commodity';
                            });
                        }
                    }
                });
            }
        });
    </script>
    {{--下载模板文件的js--}}
    <script>
        //rfid仓库信息异步导入
        function fileupload(){
            $('#formlist').ajaxSubmit({
                url:'/admin/rfidmanage/houseimport',
                dataType:'json',
                type:'post',
                data:$('#formlist').fieldSerialize(),
                success:function(res){
                    if (res.status == 0) {
                        var input = document.getElementById('fileinput');
                        input.value='';
                        layer.msg(res.msg);
                    } else {
                        layer.msg(res.msg, {icon: 1}, function () {
                            location.href = '/admin/rfidmanage/warehouse';
                        });
                    }

                },
                error:function(xhr, type){
                    layer.msg('请检查导入的excel表格式是否正确');
                    var input = document.getElementById('fileinput');
                    input.value='';
                }
            });
        }
        //模板下载
        function downloadExcel(){
            //获取服务器地址
            var host = location.host;
            //把excel发送出来
            var url = "http://"+ host +"/admin/rfidmanage/housedownload";
            window.open(url);
        }
    </script>
@endsection